<!DOCTYPE html>
<html lang="en" class="h100">
<head>
    <title>{$web_title}</title>
    {include file='public/public_head' /}
</head>
<body>
<div class="main-wrap comment-wrap">
    <div class="content">
        <div class="comment-action-wrap">
            <div class="btn-item close-btn-item pos-a icon icon-close"></div>
            <div class="comment-title-wrap">立即投票</div>
            <!-- rating -->
            <div class="comment-item-wrap">
                <div class="item-title-wrap flex rcs">
                    <div class="item-title-line"></div>
                    <div class="item-title">
                        <span class="title">评分级别：</span>
                        <span class="title-value"></span>
                    </div>
                </div>
                <div class="item-content-wrap comment-rating-wrap flex ccc"></div>
            </div>
            <!-- btn-wrap -->
            <div class="btn-wrap submit-btn-wtap">
                <div class="btn-item submit-btn-item flex ccc" id="submitBtnItem">提交投票</div>
            </div>
        </div>
    </div>
</div>
{include file='public/footer' /}

<script src="__COMMON__/layui/layui.js"></script>
<script>
    layui.use(['rate', 'layer'], function () {
        let rate = layui.rate;
        let layer = layui.layer;
        let selectTags = [];
        let ratingValue = 3;

        rate.render({
            elem: '.comment-rating-wrap',
            half: true,
            setText: function(value){
                $('.title-value').text(value * 2 + '分');
            },
            value: ratingValue,
            choose: function (value) {
                console.log('value---->', value);
                ratingValue = value;
            }

        });

        $('.close-btn-item').on('click', function () {
            console.log('parent.layer---->', parent.layer);
            parent.layer.closeAll();
        });

        $('#submitBtnItem').on('click', function () {
            var uid = {$uid};
            var aid = {$aid};
            var sid = {$sid};
            var url = '{:url("submitVote")}';
            var data = {
                uid,
                aid,
                sid,
                score: ratingValue * 2,
            };

            $.post(url, data, function(result) {
                layer.msg(result.msg);
                if (result.code === 1) {
                    setTimeout(function() {
                        parent.location.reload();
                    }, 1000);
                }
            });
        });
    });


</script>
</body>
</html>